import java.util.HashMap;
import java.util.Map;

public class Id {
	
	private static Map<String, Id> idList = new HashMap<String, Id>();
	private String name;
	private int value;
	
	private Id(String name){
		this.name = name;
		this.value = 0;
	}
	
	private Id(String name, int value) {
		this.name = name;
		this.value = value;
	}
	
	private int getValue(){
		return this.value;
	}

	public static Map<String, Id> getIdList(){
		return idList;
	}
	
	public static void parseID(Tokens tokens) {
		if (!idList.containsKey(tokens.idName())) {
			idList.put(tokens.idName(), new Id(tokens.idName()));
		}
		tokens.skipToken();
	}
	
	public static void updateID(String name, int value) {
		// check that the ID exists
		if (idList.containsKey(name)) {
			Id tmp = new Id(name, value);
			idList.remove(name);
			idList.put(name, tmp);
		} else {
			System.err.println("This ID does not exist for assignment: " + name);
			System.exit(0);
		}
	}
	
	public static int getVal(String name) {
		int value = 0;
		if (idList.containsKey(name)) {
			Id tmp = idList.get(name);
			value = tmp.getValue();
		} else {
			System.err.println("This ID does not exist :" + name);
			System.exit(0);
		}
		return value;
	}
}